function f = elast_blp(theta2,v,x2,p,delta,ind_market,sj,QI)
%global rna
ns=length(v);
numobs=length(delta);
expdelta=exp(delta);
nmrkt=max(ind_market);
%recover price

alpha=theta2(1,1);
sigmap=theta2(1,end);
ddelt=alpha+sigmap*repmat(v(1,:),numobs,1); 
expmu1=expmu(theta2,v,x2,p);  

s1=ind_shares(expdelta,expmu1,QI,ind_market); 

A2=cell(1,1,nmrkt); 
%A2=zeros(numobs,numobs); 

for q=1:nmrkt 
    tempp=(ind_market==q);
    s11=s1(tempp,:);
    s11star=s11.*ddelt(tempp,:);
    A2{1,1,q}=(p(tempp)./sj(tempp)').*(diag(-mean(s11star.*(1-s11),2))+(1-eye(size(s11,1),size(s11,1))).*(s11star*s11'./ns)); 
end
f=A2;